package com.iot08.api.service;


import com.alibaba.fastjson.JSONObject;
import com.iot08.api.vo.request.ScreensaverLibraryReqVo;
import com.iot08.common.entity.app.ScreensaverLibrary;
import com.iot08.common.service.base.BaseAdminService;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * @author cwj
 * @description
 * @date 2024/12/21 10:55
 **/
@Slf4j
@Service
public class ScreensaverLibraryService extends BaseAdminService<ScreensaverLibrary> {

    /**
     * @description 查询屏保信息
     * @author cwj
     * @param []
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/21 11:06
     **/
    public ResponseMap queryScreensaverLibrary(String imei){
        ResponseMap res = ResponseMap.success();
        //查询设备所属models
        //todo
        Query query = new Query();
        query.fields().include("imageUrl");
        List<JSONObject> jsonObjects = mongoTemplate.find(query,JSONObject.class,"screensaver_library");
        res.put("images",jsonObjects);
        return res;
    }

    /**
     * @description 保存屏保图片库数据
     * @author cwj
     * @param [vo]
     * @return com.iot08.common.utils.response.ResponseMap
     * @date @time 2024/12/21 11:47
     **/
    public ResponseMap saveScreensaverLibrary(ScreensaverLibraryReqVo vo){
        ScreensaverLibrary screensaverLibrary = new ScreensaverLibrary();
        Date date = new Date();
        screensaverLibrary.setImageUrl(vo.getImageUrl());
        screensaverLibrary.setType(vo.getType());
        screensaverLibrary.setCreateTime(date);
        screensaverLibrary.setUpdateTime(date);
        this.save(screensaverLibrary);
        return ResponseMap.success();
    }


}
